home *** CD-ROM | disk | FTP | other *** search
Wrap
RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhSSSSeeeettttIIIItttteeeerrrraaaattttoooorrrr((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhSSSSeeeettttIIIItttteeeerrrraaaattttoooorrrr((((3333CCCC++++++++)))) NNNNaaaammmmeeee RWTPtrHashSetIterator<T,H,EQ> - Rogue Wave library class SSSSyyyynnnnooooppppssssiiiissss #include<rw/tphset.h> RWTPtrHashSet<T,H,EQ> m; RWTPtrHashSet<T,H,EQ> itr(m); PPPPlllleeeeaaaasssseeee NNNNooootttteeee!!!! IIIIffff yyyyoooouuuu hhhhaaaavvvveeee tttthhhheeee SSSSttttaaaannnnddddaaaarrrrdddd CCCC++++++++ LLLLiiiibbbbrrrraaaarrrryyyy,,,, uuuusssseeee tttthhhheeee iiiinnnntttteeeerrrrffffaaaacccceeee ddddeeeessssccccrrrriiiibbbbeeeedddd hhhheeeerrrreeee.... OOOOtttthhhheeeerrrrwwwwiiiisssseeee,,,, uuuusssseeee tttthhhheeee rrrreeeessssttttrrrriiiicccctttteeeedddd iiiinnnntttteeeerrrrffffaaaacccceeee ttttoooo RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhTTTTaaaabbbblllleeeeIIIItttteeeerrrraaaattttoooorrrr described in Appendix A. DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhSSSSeeeettttIIIItttteeeerrrraaaattttoooorrrr is supplied with TTTToooooooollllssss....hhhh++++++++ 7.x to provide an iterator interface to the Standard Library based collections that has backward compatibility with the container iterators provided in TTTToooooooollllssss....hhhh++++++++ 6.x. Iteration over an RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhSSSSeeeetttt is pseudorandom and dependent on the capacity of the underlying hash table and the hash function being used. The current item referenced by this iterator is undefined after construction or after a call to rrrreeeesssseeeetttt(((()))). The iterator becomes valid after being advanced with either a pre-increment or an ooooppppeeeerrrraaaattttoooorrrr(((()))). For both ooooppppeeeerrrraaaattttoooorrrr++++++++ and ooooppppeeeerrrraaaattttoooorrrr(((()))), iterating past the last element will return a value equivalent to boolean ffffaaaallllsssseeee. Continued increments will return a value equivalent to ffffaaaallllsssseeee until rrrreeeesssseeeetttt(((()))) is called. PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee None EEEExxxxaaaammmmpppplllleeeessss #include<rw/tphset.h> #include<iostream.h> #include<rw/cstring.h> struct silly_h{ unsigned long operator()(RWCString x) const { return x.length() * (long)x(0); } }; int main(){ PPPPaaaaggggeeee 1111 RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhSSSSeeeettttIIIItttteeeerrrraaaattttoooorrrr((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhSSSSeeeettttIIIItttteeeerrrraaaattttoooorrrr((((3333CCCC++++++++)))) RWTPtrHashSet <RWCString,silly_h,equal_to<RWCString> > age; RWTPtrHashSetIterator <RWCString,silly_h,equal_to<RWCString> > itr(age); age.insert(new RWCString("John")); age.insert(new RWCString("Steve")); age.insert(new RWCString("Mark")); //Duplicate insertion is rejected age.insert(new RWCString("Steve")); for(;++itr;) cout << *itr.key() << endl; return 0; } Program Output (not necessarily in this order) John Mark Steve PPPPaaaaggggeeee 2222 RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhSSSSeeeettttIIIItttteeeerrrraaaattttoooorrrr((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhSSSSeeeettttIIIItttteeeerrrraaaattttoooorrrr((((3333CCCC++++++++)))) PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrrssss RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhSSSSeeeettttIIIItttteeeerrrraaaattttoooorrrr<<<<TTTT,,,,HHHH,,,,EEEEQQQQ>>>>(RWTPtrHashSet<T,H,EQ>&h); Creates an iterator for the hashed set hhhh. The iterator begins in an undefined state and must be advanced before the first element will be accessible. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr OOOOppppeeeerrrraaaattttoooorrrrssss T* ooooppppeeeerrrraaaattttoooorrrr(((())))(); Advances self to the next element, dereferences the resulting iterator and returns its value. If the iterator has advanced past the last item in the container, the element returned will be a nnnniiiillll pointer equivalent to boolean ffffaaaallllsssseeee. RWBoolean ooooppppeeeerrrraaaattttoooorrrr++++++++(); Advances self to the next element. If the iterator has been reset or just created self will now reference the first element. If, before iteration, self referenced the last association in the multi-map, self will now point to an undefined value and a value equivalent to ffffaaaallllsssseeee will be returned. Otherwise, a value equivalent to ttttrrrruuuueeee is returned. Note: no post-increment operator is provided. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss RWTPtrHashSet<T,H,EQ>* ccccoooonnnnttttaaaaiiiinnnneeeerrrr(((()))) const; Returns a pointer to the collection being iterated over. T* kkkkeeeeyyyy() const; Returns the element referenced by sssseeeellllffff. Undefined if self is not referencing a value within the set. void rrrreeeesssseeeetttt(); void rrrreeeesssseeeetttt(RWTPtrHashSet<T,H,EQ>& h); Resets the iterator so that after being advanced it will reference the first element of the collection. Using rrrreeeesssseeeetttt(((()))) with no argument will reset the iterator on the current container. Supplying a RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhSSSSeeeetttt PPPPaaaaggggeeee 3333 RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhSSSSeeeettttIIIItttteeeerrrraaaattttoooorrrr((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrHHHHaaaasssshhhhSSSSeeeettttIIIItttteeeerrrraaaattttoooorrrr((((3333CCCC++++++++)))) to rrrreeeesssseeeetttt(((()))) will reset the iterator on that container. PPPPaaaaggggeeee 4444